home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / starfield.bb < prev    next >
Encoding:
Text File  |  2002-04-10  |  1.5 KB  |  66 lines

  1. ;Starfield demo
  2. ;Copyright ⌐2000 EdzUp
  3. ;written by Ed Upton
  4. ;Graphics 'Borrowed' from Mark Sibly's stars.bmp
  5.  
  6. ;adjust for more or less stars (500 looks nice)
  7. ;I can get 2500 stars without losing a single frame
  8. Global staramount=1000
  9.  
  10. Graphics 640,480
  11. SetBuffer BackBuffer()
  12.  
  13. Global stara=LoadImage("graphics\star1.bmp")
  14. Global starb=LoadImage("graphics\star2.bmp")
  15. Global starc=LoadImage("graphics\star3.bmp")
  16.  
  17. ;star array
  18. Type star
  19.  Field rad,speed,angle
  20. End Type
  21.  
  22. setupstars()
  23.  
  24. ;main loop
  25. While Not KeyDown(1)
  26.  Cls
  27.  update()
  28.  Flip
  29. Wend
  30. End
  31.  
  32. ;set up stars
  33. Function setupstars()
  34.  For sc=0 To staramount
  35.   stars.star = New star
  36.   stars\rad=Rnd(280)+80
  37.   stars\angle=Rnd(65535)
  38.   stars\speed=Rnd(5)+1
  39.  Next
  40. End Function
  41.  
  42. ;update each star in turn
  43. Function update()
  44.  For stars.star = Each star
  45.   xx=320+Sin((2*stars\angle)*Pi/360)*stars\rad
  46.   yy=240+Cos((2*stars\angle)*Pi/360)*stars\rad
  47.   ;replace star if it goes off screen
  48.   If xx<0 Or xx>639 Or yy<0 Or yy>480
  49.    stars\rad=Rnd(40)+40
  50.    stars\angle=Rnd(65535)
  51.    stars\speed=Rnd(5)+1
  52.   EndIf
  53.   stars\rad=stars\rad+(stars\speed*2)
  54.   If stars\speed=1 Then DrawImage starc,xx,yy
  55.   If stars\speed=2 Or stars\speed=3 Then DrawImage starb,xx,yy
  56.   If stars\speed>3 Then DrawImage stara,xx,yy
  57. ;  If stars\speed=1 Then Color 50,50,50
  58. ;  If stars\speed=2 Then Color 100,100,100
  59. ;  If stars\speed=3 Then Color 150,150,150
  60. ;  If stars\speed=4 Then Color 200,200,200
  61. ;  If stars\speed=5 Then Color 250,250,250
  62. ;  Plot xx,yy
  63.  Next
  64.  Color 0,0,0
  65.  Oval 260,180,120,120
  66. End Function